<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<jsp:useBean id="databaseBean" scope="session"
	class="warehouse.DatabaseBean" />

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>订单详情</title>

<link rel="stylesheet" href="layui/css/layui.css">
<script src="layui/layui.js"></script>
</head>
<body>
	<a href="order_list.jsp" class="layui-btn"><i class="layui-icon layui-icon-return"></i>返回订单列表</a>
	<%
		String orderNoString = request.getParameter("orderNo");

		if (orderNoString == null) {
			//如果没有传入此参数，则跳转回一览表
			response.sendRedirect("order_list.jsp");
		}
	%>
	<h1 style="text-align: center">订单详情</h1>
	<div class="layui-tab layui-tab-brief">
		<ul class="layui-tab-title">
			<li class="layui-this">订单信息</li>
			<li>预订货物</li>
		</ul>
		<div class="layui-tab-content">
			<!-- 订单信息 -->
			<div class="layui-tab-item layui-show">
			<table class="layui-table" lay-even>
				<thead>
				<tr>
					<th>订单号</th>
					<th>下单日期</th>
					<th>客户编号</th>
					<th>联系人</th>
					<th>客户联系方式</th>
					<th>订单状态</th>
				</tr>
				</thead>
			<%
				String sql=String.format(
						"SELECT * FROM orders,client WHERE orders.clientNo=client.clientNo AND orderNo='%s'", orderNoString);
				ResultSet rs=databaseBean.executeQuery(sql);
				while(rs.next()){
					%>
					<tr>
						<td><%=rs.getString("orderNo")  %></td>
						<td><%=rs.getString("orderDate")  %></td>
						<td><%=rs.getString("clientNo")  %></td>
						<td><%=rs.getString("name")  %></td>
						<td><%=rs.getString("telenumber")  %></td>
						<td><%=rs.getInt("state")==0?"未完成":"已完成"%></td>	
					</tr>	
					<%
				}
				rs.close();
				%>
			</table>
			
			</div>
			<!-- 预订货物 -->
			<div class="layui-tab-item">
				<table class="layui-table" lay-even>
					<thead>
					<tr>
						<th>货物编号</th>
						<th>名称</th>
						<th>单价(元)</th>
						<th>库存量(件)</th>
						<th>购买量(件)</th>
						<th>小计（元）</th>
					</tr>
					</thead>
				<%
					sql=String.format(
							"SELECT cargo.cargoNo,name,price,inventory,purchaseNum FROM cargo,cargo_order WHERE cargo.cargoNo=cargo_order.cargoNo AND orderNo='%s';",
							orderNoString);
					rs=databaseBean.executeQuery(sql);
					double sumPrice = 0;
					while(rs.next()){
						%>
						<tr>
							<td><%=rs.getString("cargoNo")  %>	</td>
							<td><%=rs.getString("name")  %>		</td>
							<td><%=rs.getString("price")  %></td>
							<td><%=rs.getString("inventory")  %></td>
							<td><%=rs.getString("purchaseNum")  %></td>
							<td><%=rs.getFloat("price")*rs.getInt("purchaseNum") %>
						</tr>		
						<%
						sumPrice +=rs.getFloat("price")*rs.getInt("purchaseNum");
					}
					rs.close();
					%>
					<tr>
						<td>总计（元）</td>
						<td colspan="5"><%=sumPrice %></td>
					</tr>
				</table>
			
			</div>
			

		</div>
	</div>

	<script>
		//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
		layui.use('element', function() {
			var element = layui.element;
		});
	</script>
</body>
</html>